#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>
#include "tree.h"

using namespace std;

int sumInRange(Tree *root, int lo, int hi)
{
    int ans = 0;
    if (!root) return ans;
    if (root->data >= lo && root->data <= hi) 
        ans += root->data;
    if (root->data < lo) 
        return ans + sumInRange(root->right, lo, hi);
    if (root->data > hi) 
        return ans + sumInRange(root->left, lo, hi);
    return ans + sumInRange(root->right, lo, hi) + sumInRange(root->left, lo, hi);
}

int main(int argc, char **argv)
{
    int input[] = {24, 54,4,56,98,34,56,7,5,6,3,2,8,10,11,35,56};
    //int input[] = {7};
    Tree *root = NULL, *root2 = NULL;
    vector<Tree *> result;

    for (int i = 0; i < sizeof(input)/sizeof(int); i++) {
        TreeInsert(root, input[i]);
    }

    print_ascii_tree(root);
    cout << sumInRange(root, 4, 60) << endl;
    cout << sumInRange(root, 4, 8) << endl;
    cout << sumInRange(root, 17,19) << endl;
}
